<template>
  <el-card style="margin:10px 0">
    <div class="clearfix">
      <el-tabs v-model="activeName">
        <el-tab-pane label="用户管理" name="first" />
        <el-tab-pane label="配置管理" name="second" />
      </el-tabs>
      <!-- 头部右侧内容 -->
      <div class="right">
        <span @click="setDay">今日</span>
        <span @click="setWeek">本周</span>
        <span @click="setMonth">本月</span>
        <span @click="setYear">本年</span>

        <el-date-picker
          v-model="date"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
      </div>
    </div>
    <!-- 内容区域 -->
    <div>
      <el-row :gutter="10">
        <el-col :span="17">
          <h3>{{ title }}趋势</h3>
          <div ref="charts" class="chart" />
        </el-col>
        <el-col :span="7">
          <h3>门店{{ title }}排名</h3>
          <ul>
            <li>
              <span class="rindex">1</span>
              <span class="text">肯德基</span>
              <span class="rnumber">123456</span>
            </li>
            <li>
              <span class="rindex">2</span>
              <span class="text">肯德基</span>
              <span class="rnumber">123456</span>
            </li>
            <li>
              <span class="rindex">3</span>
              <span class="text">肯德基</span>
              <span class="rnumber">123456</span>
            </li>
            <li>
              <span class="rindex">4</span>
              <span class="text">肯德基</span>
              <span class="rnumber">123456</span>
            </li>
            <li>
              <span class="rindex">5</span>
              <span class="text">肯德基</span>
              <span class="rnumber">123456</span>
            </li>
            <li>
              <span class="rindex">6</span>
              <span class="text">肯德基</span>
              <span class="rnumber">123456</span>
            </li>
            <li>
              <span class="rindex">7</span>
              <span class="text">肯德基</span>
              <span class="rnumber">123456</span>
            </li>
          </ul>
        </el-col>
      </el-row>
    </div>
  </el-card>
</template>

<script>
import * as echarts from 'echarts'
import dayjs from 'dayjs'
export default {
  data() {
    return {
      activeName: 'first',
      date: '',
      charts: null
    }
  },
  computed: {
    title() {
      return this.activeName === 'first' ? '销售额' : '访问量'
    }
  },
  //   watch: {
  //     title() {
  //       // 重新修改图表配置数据
  //     }
  //   },
  mounted() {
    this.charts = echarts.init(this.$refs.charts)
    this.charts.setOption({
      xAxis: {
        type: 'category',
        data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月']
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [120, 200, 150, 80, 70, 110, 130, 120, 200, 150, 80, 70],
          type: 'bar',
          showBackground: true,
          backgroundStyle: {
            color: 'rgba(180, 180, 180, 0.2)'
          }
        }
      ],
      tooltip: {
        show: true
      },
      grid: {
        left: '3%',
        right: '4%',
        bottom: '10%'
      }
    })
  },
  methods: {
    setDay() {
      const day = dayjs().format('YYYY-MM-DD')
      this.date = [day, day]
    },
    setWeek() {
      // 获取本周第一天
      const start = dayjs().day(1).format('YYYY-MM-DD')
      // 获取本周最后一天
      const end = dayjs().day(7).format('YYYY-MM-DD')
      this.date = [start, end]
    },
    setMonth() {
      // 本月第一天
      const start = dayjs().startOf('month').format('YYYY-MM-DD')
      // 本月最后一天
      const end = dayjs().endOf('month').format('YYYY-MM-DD')
      this.date = [start, end]
    },
    setYear() {
      // 今年第一天
      const start = dayjs().startOf('year').format('YYYY-MM-DD')
      // 今年最后一天
      const end = dayjs().endOf('year').format('YYYY-MM-DD')
      this.date = [start, end]
    }
  }
}
</script>

<style scoped>
.clearfix{
    display: flex;
    justify-content: space-between;
    position: relative;
}

.el-tabs{
    width: 100%;
}

.right{
    position: absolute;
    right: 0;
}

.right span{
    margin: 0 20px;
}

.chart{
    width: 100%;
    height: 300px;
}

ul{
    list-style: none;
    width: 100%;
    height: 300px;
    padding-inline-start: 0;
}

ul li{
    height: 8%;
    margin: 20px 0;
}

.rindex{
    float: left;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #000;
    color: #fff;
    text-align: center;
}

.rnumber{
    float: right;
}

.text{
    margin: 0 20px;
}
</style>
